#!/usr/bin/env python3
# coding:utf-8
import requests
# 网关base_url
# server_url = 'http://0.0.0.0:8080/iot/gateway/'
# 传感器base_url
# server_url = 'http://0.0.0.0:8080/iot/sensor/'
server_url = 'http://0.0.0.0:8080/iot/sensor_type/'
# s = requests.session()
# column = ['name=:name', 'sex=:sex', 'id_card=:id_card', 'city_id=:city_id']
# sql = 'UPDATE {} SET {} WHERE id=:id'.format('t', ','.join(column))


def test_editGateway():
    data = {'id': 4, 'name': "12", 'code': '12'}
    url = server_url + 'editGateway'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())

def delGateway():
    data = {'id': 4, 'name': "12", 'code': '12'}
    url = server_url + 'delGateway'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(r.json())

# 怎么会自己自动由post重定向到get方法??????
def test_get_sensor_by_device():
    data = {'id': 2}
    url = server_url + 'get_all_by_device_id'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(r.json())

def test_get_sensor_by_device_id():
    data = {'id': 2}
    url = server_url + 'get_all_by_sensor_type_id'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(r.json())

################传感器类型

def test_add_type():
    data = {'id': 2, 'name': "12", 'code': '12'}
    url = server_url + 'add'
    headers = {'Content-Type': 'application/json'}
    r = requests.post(url, json=data, headers=headers)
    print(type(r))
    print(r.json())


# test_editGateway()
# delGateway()
# test_get_sensor_by_device()
# test_get_sensor_by_device_id()
test_add_type()

if __name__ == '__main__':
    pass

